import { bookModel } from '../../model/bookModel.js'
const bookMode = new bookModel()
// components/bookList/index.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    books: {
      type: Object
    },
    detail:{
      type:Object
    }
  },
  /**
   * 组件的初始数据
   */

  data: {
    searchImg: '/components/bookList/image/search@2x.png',
    chooseImg: '/components/bookList/image/choose@2x.png',
    showContainer:true,
    showDetail:false,
    showSearch:false
  },
  /**
   * 组件的方法列表
   */
  attached:function(){  
  },
  methods: {
    ondetail:function(e){
      this.setData({
        detail:e.detail.info,
        showDetail:true,
        showContainer:false,
        showSearch: false
      })
      // console.log(e)
    },
    onShowSearch:function(e){
      this.setData({
        showDetail: false,
        showContainer: false,
        showSearch: true,
      })
      console.log("SADA")
    },
    onCloseDetail:function(){
      this.setData({
        showDetail: false,
        showContainer: true,
        showSearch: false,
      })
    },
    
    onShowContainer: function () {
      this.setData({
        showDetail: false,
        showContainer: true,
        showSearch: false,
      })
    },
    getKeyword:function(e){
      // console.log(e.detail.keywordValue)
      const book = bookMode.getHotList(e.detail.keywordValue)
      book.then(
        (res) => {
          // console.log(res.data)
          this.setData({
            books: res.data.data,
            showDetail: false,
            showContainer: true,
            showSearch: false
          })
          console.log(res.data.data)
        }) 
    },
   onGetTag:function(e){
     console.log(e.detail.keyword)
      let book = bookMode.getHotList(e.detail.keyword)
      book.then(
        (res) => {
          // console.log(res.data)
          this.setData({
            books: res.data.data,
            showDetail: false,
            showContainer: true,
            showSearch: false
          })
          // console.log(res.data.data)
        })
   },
    onGetSearchList:function(e){
      console.log(e.detail.listName)
      let book = bookMode.getHotList(e.detail.listName)
      book.then(
        (res) => {
          // console.log(res.data)
          this.setData({
            books: res.data.data,
            showDetail: false,
            showContainer: true,
            showSearch: false
          })
        })
    }
    }
    },
  
)